package service.impl;

import entity.AdminDO;
import service.AdminService;
import util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class AdminServiceImp implements AdminService {
    @Override
    public boolean validatAdmin(AdminDO adminDO) {
        String userName=adminDO.getUsername();
        String pwdParam=adminDO.getPwd();
        String sql="select pwd from manager where user_name=?";
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet resultSet=null;
        try{
             conn=DBUtil.getConn();
             if(conn==null){
                 return false;
             }
             ps=conn.prepareStatement(sql);
            ps.setString(1, userName);
            resultSet=ps.executeQuery();
            while (resultSet.next()){
                String pwd=resultSet.getString(1);
                if(adminDO.getPwd().equals(pwd)){
                    return true;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        finally {
            DBUtil.closeRs(resultSet);
            DBUtil.closeConn(conn);
            DBUtil.closePs(ps);
        }
        return false;
    }
}
